import { nextTick } from '../util/next-tick.js';

let queue = [];
let has = {};

function flushSchedularQueue() {
  queue.forEach(watcher => watcher.run())
  queue = []
  has = {}
}

export function queueWatcher(watcher) {
  const id = watcher.id
  if(has[id] == null) {
    has[id] = true
    queue.push(watcher)
    // 红任务 和 微任务
    nextTick(flushSchedularQueue)
  }
}